package com.example.demo.serviceImpl.bug;

import com.example.demo.dao.bug.BugDao;
import com.example.demo.dao.bug.BugPictureDao;
import com.example.demo.dao.coreport.CoreportBugDao;
import com.example.demo.dao.coreport.CoreportDao;
import com.example.demo.dao.coreport.CoreportReplyDao;
import com.example.demo.dao.coreport.CoreportWorkerDao;
import com.example.demo.dao.opt.OptDao;
import com.example.demo.dao.report.ReportBugDao;
import com.example.demo.dao.user.UserDao;
import com.example.demo.po.bug.Bug;
import com.example.demo.po.opt.Opt;
import com.example.demo.po.picture.Picture;
import com.example.demo.service.bug.BugService;
import com.example.demo.vo.bug.BugInfoVO;
import com.example.demo.vo.bug.BugVO;
import com.example.demo.vo.ResultVO;
import com.example.demo.vo.coreport.CoreportInfoVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class BugServiceImpl implements BugService {
    @Resource
    BugDao bugDao;
    @Resource
    OptDao optDao;
    @Resource
    ReportBugDao reportBugDao;
    @Resource
    BugPictureDao bugPictureDao;
    @Resource
    CoreportBugDao coreportBugDao;

    @Override
    public ResultVO<List<BugInfoVO>> getInfoByReport(int rid) {
        if(reportBugDao.selectBugByReport(rid)==null){
            return(new ResultVO<List<BugInfoVO>>(-1,"未找到报告",null));
        }
        List<BugInfoVO> res = new ArrayList<BugInfoVO>();
        for(Bug bug:reportBugDao.selectBugByReport(rid)){
            BugInfoVO bugInfoVO = new BugInfoVO(bug);
            for(Picture picture:bugPictureDao.getPictureByBug(bug.getBid())){
                bugInfoVO.addPicture(picture);
            }
            res.add(bugInfoVO);
        }
        return new ResultVO<List<BugInfoVO>>(1,"查询成功",res);
    }

    @Override
    public ResultVO<List<BugInfoVO>> getInfoByCoreport(int coid) {
        if(coreportBugDao.selectBugByCoreport(coid)==null){
            return(new ResultVO<List<BugInfoVO>>(-1,"未找到报告",null));
        }
        List<BugInfoVO> res = new ArrayList<BugInfoVO>();
        for(Bug bug:coreportBugDao.selectBugByCoreport(coid)){
            BugInfoVO bugInfoVO = new BugInfoVO(bug);
            for(Picture picture:bugPictureDao.getPictureByBug(bug.getBid())){
                bugInfoVO.addPicture(picture);
            }
            res.add(bugInfoVO);
        }
        return new ResultVO<List<BugInfoVO>>(1,"查询成功",res);
    }

    @Override
    public int insertBug(BugVO bugVO) {
        return bugDao.insertBug(bugVO);
    }


    public List<Opt> getOpt(){
        return optDao.selectOpt();
    }

}
